<template>
  <div>
    <h1>文件管理</h1>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column
        prop="articleId"
        label="文章ID"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="articleTitle"
        label="文章标题"
        width="180"
      ></el-table-column>
      <el-table-column prop="documentSrc" label="文件">
        <template slot-scope="scope">
          <img :src="scope.row.documentSrc" height="80" width="100" alt="" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="adopt(scope.$index, scope.row)"
          >
            通过
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="noAdopt(scope.$index, scope.row)"
          >
            不通过
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { checkArticle, getDocumentList, checkFile } from '@/api/bbs'
  export default {
    name: 'Index',
    data() {
      return {
        tableData: [
          {
            documentId: '',
            articleId: '',
            articleTitle: '',
            documentSrc: '',
          },
        ],
      }
    },
    mounted() {
      this.getFiles()
    },
    methods: {
      getFiles() {
        getDocumentList().then((res) => {
          console.log(res)
          this.tableData = res.data
        })
      },
      adopt(index, row) {
        console.log(index, row)
        checkFile(1, row).then((res) => {
          this.getFiles()
          console.log(res)
        })
      },
      noAdopt(index, row) {
        console.log(index, row)
        checkFile(2, row).then((res) => {
          this.getFiles()
          console.log(res)
        })
      },
    },
  }
</script>

<style scoped></style>
